import java.awt.*;
import java.awt.event.*;

public class Menu {
	
	private GameInterface gi;
	private Phase owner;
	private Menu previous;
	
	//private String title;
	private int x, y;
	private int width, depth;
	
	private Button[] b;
	
	public Menu(Phase cp){
		owner = cp;
		gi = cp.getGameInterface();
		Point p = gi.getInsetAdjustment();
		x = (int)p.getX();
		y = (int)p.getY();
		Dimension d = gi.getDimensions();
		width = (int)d.getWidth();
		depth = (int)d.getHeight();
		previous = null;
	}
	
	public void update(long l){}
	public void display(Graphics2D g){}
	
	public boolean mouseInput(MouseEvent me){
		boolean hitSomething = false;
		if(b != null)
		{
			for(int i=0;i<b.length;i++)
			{
				if(b[i] != null)
				{
					if(b[i].getEnabled())
					{
						if(b[i].mouseInput(me))
							hitSomething = true;
					}
				}
			}
		}
		return hitSomething;
	}
	public boolean keyInput(KeyEvent ke){
		boolean hitSomething = false;
		if(b != null)
		{
			for(int i=0;i<b.length;i++)
			{
				if(b[i] != null)
				{
					if(b[i].getEnabled())
					{
						if(b[i].keyInput(ke))
							hitSomething = true;
					}
				}
			}
		}
		return hitSomething;
	}
	
	public GameInterface getGameInterface(){return gi;}
	public Phase getOwner(){return owner;}
	public Menu getPrevious(){return previous;}
	public int getX(){return x;}
	public int getY(){return y;}
	public int getWidth(){return width;}
	public int getDepth(){return depth;}
	public Button[] getButtonArray(){return b;}
	public Button getButtonAt(int gbap){
		if((gbap >= 0) && (gbap <= b.length))
			return b[gbap];
		else
			return null;
	}
	
	public void setGameInterface(GameInterface sgi){gi = sgi;}
	public void setOwner(Phase so){owner = so;}
	public void setPrevious(Menu sp){previous = sp;}
	public void setX(int sx){x = sx;}
	public void setY(int sy){y = sy;}
	public void setWidth(int sw){width = sw;}
	public void setDepth(int sd){depth = sd;}
	public void setButtonArray(Button[] sba){b = sba;}
	public void setButtonAt(Button sba, int sbap){
		if((b != null) && (sba != null))
		{
			if((sbap >=0) && (sbap <= b.length))
			{
				b[sbap] = sba;
			}
		}
	}
}
